<?php

/**
 * Description of favorite
 * 
 * @author 叶风
 * Qq:    355007778
 * Email: ye.fn@163.com
 */

namespace c\user;
\YF_f::initC('\c\auth\permission')->login();

class favorite extends \control
{
    var $table = 'user_favorite';
    
	function index_add()
    {
        $data = $_POST['d'];
        $data['time'] = UNIX_TIME;
        $data['user_id'] = \YF_f::$login_user_id;
        if (!isset($data['des']))
            $data['des'] = '';
        if (!isset($data['pic']))
            $data['pic'] = '';
        
        $db = $this->db;
        $b = $db->getOne($this->table, 'id', 'user_id='. $data['user_id'] .' AND url="'. $db->escape($data['url']) .'" AND pic="'. $db->escape($data['pic']) .'" AND des="'. $db->escape($data['des']) .'"');
        if (!$b)
            $b = $db->save($this->table, $data);
        ajax_json($b ? TRUE : \lang::g('save fail'));
    }
    function index_home()
    {
        $this->title = \lang::g('Favorite');
        $res = $this->db->get_page(array(), $this->table, '*', 'user_id='. \YF_f::$login_user_id);
        $this->loadTemplate('user/favorite', array('res'=>$res));
        $this->display('user');
    }
    function index_del()
    {
        $id = intval($_GET['id']);
        $b = $this->db->del($this->table, "id IN($id) AND user_id=". \YF_f::$login_user_id);
		if ($b)
		 {
			\log::write($this->table, 'del', $id);
			ajax_json(TRUE);	
		 }
		ajax_json(\lang::g( 'Over'));
    }
}
